<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title th:text="${news.title} + ' - 新闻分析系统'">新闻详情</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.8.1/font/bootstrap-icons.css" rel="stylesheet">
</head>
<body class="bg-light">
    <nav class="navbar navbar-expand-lg navbar-dark bg-primary">
        <div class="container">
            <a class="navbar-brand" href="/">新闻分析系统</a>
            <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav">
                <span class="navbar-toggler-icon"></span>
            </button>
            <div class="collapse navbar-collapse" id="navbarNav">
                <ul class="navbar-nav">
                    <li class="nav-item">
                        <a class="nav-link" href="/news">新闻列表</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="/analysis/hot">热度分析</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="/analysis/category">分类分析</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="/analysis/sentiment">情感分析</a>
                    </li>
                </ul>
            </div>
        </div>
    </nav>

    <div class="container my-4">
        <div class="card shadow">
            <div class="card-body">
                <th:block th:if="${news != null}">
                    <div class="d-flex justify-content-between align-items-center mb-4">
                        <div>
                            <span class="badge bg-primary me-2" th:text="${news.category != null ? news.category : '未分类'}">类别</span>
                            <span th:class="'badge me-2 ' + (${news.sentiment == '正面' ? 'bg-success' : (news.sentiment == '负面' ? 'bg-danger' : 'bg-secondary')})"
                                  th:text="${news.sentiment != null ? news.sentiment : '未分析'}">情感</span>
                            <span class="badge bg-info" th:text="'热度: ' + ${news.hotIndex != null ? news.hotIndex : '0'}">热度</span>
                        </div>
                        <div class="text-muted">
                            <i class="bi bi-calendar me-1"></i>
                            <span th:text="${news.publishTime != null ? #temporals.format(news.publishTime, 'yyyy-MM-dd HH:mm') : '未知日期'}">发布日期</span>
                        </div>
                    </div>

                    <h1 class="card-title mb-4" th:text="${news.title}">新闻标题</h1>
                    
                    <div class="card-text news-content mb-4">
                        <th:block th:if="${news.content != null && !news.content.isEmpty()}">
                            <th:block th:with="paragraphs=${#strings.arraySplit(news.content, '\\r?\\n\\r?\\n')}">
                                <p th:each="paragraph : ${paragraphs}" 
                                   th:if="${!#strings.isEmpty(paragraph)}" 
                                   th:utext="${#strings.replace(paragraph, '\\n', '<br>')}"
                                   class="mb-3">内容段落</p>
                            </th:block>
                        </th:block>
                    </div>

                    <div class="source-info mb-4">
                        <i class="bi bi-building me-1"></i>
                        来源：<span th:text="${news.source}" class="text-muted">来源</span>
                    </div>

                    <div class="d-flex gap-2">
                        <a th:if="${news.url != null && !news.url.isEmpty()}" 
                           th:href="${news.url}" 
                           target="_blank" 
                           class="btn btn-outline-primary">
                            <i class="bi bi-box-arrow-up-right me-1"></i>查看原文
                        </a>
                        <a th:href="@{/analysis/keyword(newsId=${news.id})}" 
                           class="btn btn-outline-info">
                            <i class="bi bi-tags me-1"></i>关键词分析
                        </a>
                    </div>
                </th:block>
                <div th:if="${news == null}" class="alert alert-danger">
                    <i class="bi bi-exclamation-triangle me-2"></i>无法找到新闻
                </div>
            </div>
        </div>
    </div>

    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>